<?php
/**
 * 商城报名shopnc_sign_up
 *
 */
defined('InShopNC') or exit('Access Invalid!');

class sign_upControl extends MobileControl
{
        /*
     * 美财网与消费者见面会，用户报名
     * */
    public function indexOp(){
        if(chksubmit()){
            if (check_repeat('reg',30)){
                appJump('您的操作过于频繁，请稍后再试','index.php');
            }
            $obj_validate = new Validate();
            $obj_validate->validateparam = array(
                array(
                    "input"=>$_POST["sign_name"],
                    "require"=>"true",
                    "validator"=>'Length',
                    "max"=>30,
                    "message"=>'姓名不能为空或不合法'
                ),
                array(
                    "input"=>$_POST["sign_phone"],
                    "require"=>"true",
                    "validator"=>"Custom",
                    "regexp"=>"/^(1[3578]\d{9}|((0[0-9]{2,3})-)([0-9]{7,8})(-([0-9]{3,}))?)$/",
                    "message"=>"请输入正确的电话号码"
                ),
                array(
                    "input"=>$_POST["sign_addr"],
                    "require"=>"true",
                    "validator"=>'Length',
                    "max"=>50,
                    "message"=>'地址不能为空或不合法'
                ),
                array(
                    "input"=>$_POST["sign_shop_name"],
                    "require"=>"true",
                    "validator"=>'Length',
                    "max"=>30,
                    "message"=>'店名不能为空或不合法'
                ),
            );
            $error = $obj_validate->validate();
            $error = explode("<br/>",$error);
            if ($error[0] != ''){
                appJump($error[0]);
            }
            //手机号码唯一性
            $sql = "select * from #__sign_up where sign_phone =". "'{$_POST['sign_phone']}'";
            $phone = Db::queryRow($sql);
            if($phone){
                appJump('该电话号码已存在');
            }
            //将用户信息insert into shopnc_sign_up
            $insert_array = array();
            $insert_array['sign_name'] = $_POST['sign_name'];
            $insert_array['sign_phone'] = $_POST['sign_phone'];
            $insert_array['sign_sex'] = $_POST['sign_sex'];
            $insert_array['sign_addr'] = $_POST['sign_addr'];
            $insert_array['sign_shop_name'] = $_POST['sign_shop_name'];
            $insert_array['sign_time']  =time();
            Db::insert('sign_up',$insert_array);
            appJump('报名成功','index.php');
        }
        //点击首页广告图进入一个可以报名的页面
        tpl::showpage('sign_up');
    }
//客户端ajax手机号码检测
    public function checkMobileOp() {
        //手机号码唯一性
        $sql = "select * from #__sign_up where sign_phone =". "'{$_POST['sign_phone']}'";
        $phone = Db::queryRow($sql);
        if(!empty($phone) && is_array($phone)){
            echo 'false';//表示电话号码存在
        }else {
            echo 'true';
        }
    }
}